<!-- 作者:唐嘉诚 -->
<!-- 查询院线 -->
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>显示院线</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
</head>

<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-body" style="position:absolute;left:1px;top:-10px;">
            <table class="layui-hide" id="tabStu" lay-filter="test"></table>
        </div>
    </div>
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.12.4.min.js"></script>

    <script type="text/html" id="toolbarDemo">
        <button class="layui-btn layui-btn-sm" lay-event="addCinema">添加院线</button>
        <div class="layui-input-inline">
            <input type="text" id="txtkey" placeholder="请输入关键字" autocomplete="off" class="layui-input">
        </div>
        <button class="layui-btn layui-btn-sm" lay-event="btnSubmit">查询</button>
        <button class="layui-btn layui-btn-sm" lay-event="btnReset">重置</button>
    </script>

    <script id="imgtemplet" type="text/html">
        <div>
            <img src="{{d.image}}">
        </div>
    </script>

    <script>
        layui.use(['element', 'table'], function () {
            const table = layui.table;
            const element = layui.element;
            table.render({
                elem: "#tabStu",
                url: "/api/cinema",
                page: true,
                toolbar: '#toolbarDemo',
                cols: [[
                    {
                        title: "图片",
                        templet: `#imgtemplet`,
                        width: "150",
                    },
                    {
                        field: 'name',
                        title: "院线名",
                        width: "170"
                    },
                    {
                        field: 'addr',
                        title: "地址",
                        width: "170"
                    },
                    {
                        field: 'tel',
                        title: "电话",
                        width: "120"
                    },
                    {
                        field: 'createTime',
                        title: "创建时间",
                        width: "200"
                    },
                    {
                        field: 'updateTime',
                        title: "修改时间",
                        width: "200"
                    },
                    {
                        title: "操作",
                        templet: `<div class="layui-btn-group">
                                    <button class="layui-btn layui-btn-sm" onclick="update('{{d._id}}')">
                                        <i class="layui-icon">编辑</i>
                                    </button>
                                    
                                    <button class="layui-btn layui-btn-sm" onclick="intoCount('{{d._id}}')">
                                        <i class="layui-icon">上映和场次管理</i>
                                    </button>
                                    <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delCinema('{{d._id}}',this)">
                                        <i class="layui-icon">&#xe640;</i>
                                    </button>
                                </div>`,
                        width: "290"
                    }
                ]]
            })

            //头工具栏事件
            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'addCinema':
                        location.href = "addCinema.html";
                        break;
                    case 'btnSubmit':
                        const key = $("#txtkey").val();
                        layui.table.reload("tabStu", {
                            where: {
                                key,
                            },
                            page: {
                                curr: 1
                            }
                        });
                        break;
                    case 'btnReset':
                        $("#txtkey").val("");
                        location.href = "index.html";
                        break;
                };
            });
        });
        async function update(id) {
            location.href = "./modifyCinema.html?id=" + id;
        }
        //作者：黄萌 跳转编辑场次
        async function intoCount(id) {
            location.href = "./manage.html?id=" + id;
        }
        async function delCinema(id, btn) {
            await $.ajax({
                url: "/api/Cinema/" + id,
                method: "delete",
            });
            $(btn).parents("tr").remove();
        }
    </script>
</body>

</html>